home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / pmlpp140.zip / SRC / profile.c < prev    next >
C/C++ Source or Header  |  1997-08-01  |  7KB  |  216 lines

  1. /*
  2. PMLPP - A POP3 mail "peeker" for OS/2<tm>.
  3. Copyright (C) 1997 James R. Louvau
  4.  
  5. This program is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU General Public License
  7. as published by the Free Software Foundation; either version 2
  8. of the License, or (at your option) any later version.
  9.  
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. GNU General Public License for more details.
  14.  
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software
  17. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  18.  
  19. You may contact the author of PMLPP at:
  20.  
  21. E-mail     : jim@vwm.com
  22. Snail-mail : Jim Louvau
  23.              3437 335th St.
  24.              West Des Moines, IA 50266
  25. */
  26.  
  27. #include "pmlpp.h"
  28.  
  29. static PSZ
  30. GetProfileName( )
  31. /***************/
  32. {
  33.    static CHAR szPath[ CCHMAXPATH ] = "";
  34.    PTIB        ptib;
  35.    PPIB        ppib;
  36.  
  37.    if ( ! *szPath )
  38.    {
  39.       char * p;
  40.  
  41.       DosGetInfoBlocks( &ptib, &ppib );
  42.       DosQueryModuleName(( HMODULE ) ppib->pib_hmte, sizeof( szPath ), szPath );
  43.  
  44.       p = strrchr( szPath, '.' );
  45.       if ( p )
  46.       {
  47.          strcpy( p, ".INI" );
  48.       }
  49.       else
  50.       {
  51.          strcat( szPath, ".INI" );
  52.       }
  53.    }
  54.  
  55.    return ( szPath );
  56. }
  57.  
  58. BOOL
  59. LoadProfile( HWND    hwnd,
  60.              PCONFIG pprf )
  61. /*************************/
  62. {
  63.    HINI hini = PrfOpenProfile( WinQueryAnchorBlock( hwnd ), GetProfileName( ));
  64.  
  65.    if ( hini != NULLHANDLE )
  66.    {
  67.       ULONG cbProfile = CFGSAVESIZE;
  68.       BOOL  bGotIt    = PrfQueryProfileData( hini, "PMLPP", "Config", pprf, &cbProfile );
  69.  
  70.       PrfCloseProfile( hini );
  71.  
  72.       if ( bGotIt )
  73.       {
  74.          return ( TRUE );
  75.       }
  76.    }
  77.  
  78.    return ( FALSE );
  79. }
  80.  
  81. void
  82. SaveProfile( HWND    hwnd,
  83.              PCONFIG pprf )
  84. /*************************/
  85. {
  86.    HINI hini = PrfOpenProfile( WinQueryAnchorBlock( hwnd ), GetProfileName( ));
  87.    if ( hini != NULLHANDLE )
  88.    {
  89.       CHAR szPassword[ 32 ];
  90.  
  91.       if ( ! pprf->bSavePW )
  92.       {
  93.          strcpy( szPassword, pprf->szPassword );
  94.          memset( pprf->szPassword, 0, sizeof( pprf->szPassword ));
  95.       }
  96.  
  97.       PrfWriteProfileData( hini, "PMLPP", "Config", pprf, CFGSAVESIZE );
  98.       PrfCloseProfile( hini );
  99.  
  100.       if ( ! pprf->bSavePW )
  101.       {
  102.          strcpy( pprf->szPassword, szPassword );
  103.       }
  104.    }
  105. }
  106.  
  107. MRESULT EXPENTRY
  108. ConfigDlgProc( HWND   hwnd,
  109.                ULONG  msg,
  110.                MPARAM mp1, 
  111.                MPARAM mp2  )
  112. /**************************/
  113. {
  114.    static PCONFIG pcfg = NULL;
  115.  
  116.    switch ( msg )
  117.    {
  118.       case WM_INITDLG:
  119.          {
  120.             pcfg = ( PCONFIG ) PVOIDFROMMP( mp2 );
  121.  
  122.             WinSetDlgItemText( hwnd, EF_SERVER, pcfg->szServer );
  123.             WinSetDlgItemText( hwnd, EF_USER, pcfg->szUser );
  124.             WinSetDlgItemText( hwnd, EF_PASSWORD, pcfg->szPassword );
  125.             WinSetDlgItemText( hwnd, EF_PROGRAM, pcfg->szProgram );
  126.             WinSetDlgItemText( hwnd, EF_OPTIONS, pcfg->szOptions );
  127.             WinSetDlgItemText( hwnd, EF_DIRECTORY, pcfg->szDirectory );
  128.  
  129.             WinSetDlgItemShort( hwnd, EF_PORT, pcfg->usPort, FALSE );
  130.  
  131.             if (( pcfg->ulInterval < 1L ) || ( pcfg->ulInterval > 86400L ))
  132.             {
  133.                pcfg->ulInterval = 60L;
  134.             }
  135.  
  136.             WinSendDlgItemMsg( hwnd, SPB_INTERVAL, SPBM_SETLIMITS, MPFROMLONG( 86400L ),
  137.                                MPFROMLONG( 1L ));
  138.  
  139.             WinSendDlgItemMsg( hwnd, SPB_INTERVAL, SPBM_SETCURRENTVALUE,
  140.                                MPFROMLONG( pcfg->ulInterval ), MPVOID );
  141.  
  142.             WinCheckButton( hwnd, CB_PLAYSOUND, ( pcfg->bSound ) ? 1 : 0 );
  143.  
  144.             WinCheckButton( hwnd, CB_FORCEIP, ( pcfg->bForceIP ) ? 1 : 0 );
  145.  
  146.             WinCheckButton( hwnd, CB_SAVEPASSWORD, ( pcfg->bSavePW ) ? 1 : 0 );
  147.          }
  148.          return ( MRFALSE );
  149.  
  150.       case WM_COMMAND:
  151.          {
  152.             switch ( SHORT1FROMMP( mp1 ))
  153.             {
  154.                case DID_OK:
  155.                   {
  156.                      StopPolling( pcfg );
  157.  
  158.                      WinQueryDlgItemText( hwnd, EF_SERVER, sizeof( pcfg->szServer ),
  159.                                           pcfg->szServer );
  160.                      WinQueryDlgItemText( hwnd, EF_USER, sizeof( pcfg->szUser ),
  161.                                           pcfg->szUser );
  162.                      WinQueryDlgItemText( hwnd, EF_PASSWORD, sizeof( pcfg->szPassword ),
  163.                                           pcfg->szPassword );
  164.                      WinQueryDlgItemText( hwnd, EF_PROGRAM, sizeof( pcfg->szProgram ),
  165.                                           pcfg->szProgram );
  166.                      WinQueryDlgItemText( hwnd, EF_OPTIONS, sizeof( pcfg->szOptions ),
  167.                                           pcfg->szOptions );
  168.                      WinQueryDlgItemText( hwnd, EF_DIRECTORY, sizeof( pcfg->szDirectory ),
  169.                                           pcfg->szDirectory );
  170.  
  171.                      WinQueryDlgItemShort( hwnd, EF_PORT, ( PSHORT ) &( pcfg->usPort ),
  172.                                            FALSE );
  173.  
  174.                      WinSendDlgItemMsg( hwnd, SPB_INTERVAL, SPBM_QUERYVALUE, 
  175.                                         MPFROMP( &( pcfg->ulInterval )), 
  176.                                         MPFROM2SHORT( 0, SPBQ_UPDATEIFVALID ));
  177.  
  178.                      pcfg->bSound = ( WinQueryButtonCheckstate( hwnd, CB_PLAYSOUND ) ? TRUE
  179.                                       : FALSE );
  180.  
  181.                      pcfg->bForceIP = ( WinQueryButtonCheckstate( hwnd, CB_FORCEIP ) ? TRUE
  182.                                         : FALSE );
  183.  
  184.                      pcfg->bSavePW = ( WinQueryButtonCheckstate( hwnd, CB_SAVEPASSWORD ) ? TRUE
  185.                                        : FALSE );
  186.  
  187.                      StartPolling( pcfg );
  188.  
  189.                      WinDismissDlg( hwnd, 1 );
  190.                   }
  191.                   break;
  192.  
  193.                case DID_CANCEL:
  194.                   {
  195.                      WinDismissDlg( hwnd, 0 );
  196.                   }
  197.                   break;
  198.             }
  199.          }
  200.          return ( MRZERO );
  201.    }
  202.  
  203.    return ( WinDefDlgProc( hwnd, msg, mp1, mp2 ));
  204. }
  205.  
  206. void
  207. Configure( HWND    hwnd,
  208.            PCONFIG pprf )
  209. /***********************/
  210. {
  211.    if ( WinDlgBox( HWND_DESKTOP, hwnd, ConfigDlgProc, NULLHANDLE, DLG_CONFIGURE, pprf ))
  212.    {
  213.       SaveProfile( hwnd, pprf );
  214.    }
  215. }
  216.